﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ChuanYe.CountyFireManagement.Api.Models;
using ChuanYe.CountyFireManagement.EF.MySQL.Models;
using ChuanYe.CountyFireManagement.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ChuanYe.CountyFireManagement.Api.Controllers
{
    /// <summary>
    ///  告警
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class VideoAlarmController : ControllerBase
    {
        /// <summary>
        /// 分页   
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic, dynamic> GetVideoAlarmByPage(VideoAlarmSearchRequest obj)
        {
            ResultDto<dynamic, dynamic> result = new ResultDto<dynamic, dynamic>();
            try
            {
                var page = Pickout.SetPage(obj);
                return BLL.VideoAlarmBLL.Instance.GetVideoAlarmByPage(obj.AddressCounty,obj.AddressTown,obj.AddressVillage, page);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/VideoAlarm/GetVideoAlarmByPage Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        /// 更改告警状态  
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase ChangeAuditState(ChangeAuditStateRequest obj)
        {
            ResultDtoBase result= new ResultDtoBase();
            try
            {
                int changeRows= BLL.VideoAlarmBLL.Instance.ChangeAuditState(obj.AlarmId, obj.AuditState);
                if (changeRows == -1)
                {
                    result.Status = changeRows;
                    result.Message = "AlarmId Is Null";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/VideoAlarm/ChangeAuditState Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  设置 站点下的忽略时间  
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic> AddAlarmIgnoreTime(IgnoreTimeRequest obj)
        {
            ResultDto<dynamic> result = new ResultDto<dynamic>();
            try
            {
                Alarmignoretime info = new Alarmignoretime();
                info.UserId = obj.UserId;
                info.LocaId = obj.LocaId;
                info.Value = obj.IgnoreValue;
                info.IgnoreTime = obj.StartTime ?? DateTime.Now;
                int rows= BLL.VideoAlarmBLL.Instance.AddAlarmIgnoreTime(info);
                if (rows != -1)
                {
                    result.FirstParam = info.IgnoreTime.AddMinutes(info.Value);
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/VideoAlarm/AddAlarmIgnoreTime Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  获取用户下的忽略提醒配置  
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic> GetAlarmIgnoreTime(AlarmIgnoreTimeSearchRequest obj) 
        {
            ResultDto<dynamic> result = new ResultDto<dynamic>();
            try
            {
               
                List<dynamic> list= BLL.VideoAlarmBLL.Instance.GetAlarmIgnoreTime(obj.UserId);
                result.FirstParam = list;
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/VideoAlarm/GetAlarmIgnoreTime Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

    }
}